<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/template.xhtml">
	<ui:define name="title">
		SGMF :: Veículo
	</ui:define>

	<ui:define name="content">
		<p:panel>
			<h:form id="veiculoForm">
				<h:inputHidden id="veiculoId" value="#{veiculoBean.veiculo.id}" rendered="#{veiculoBean.veiculo.id != null}" />
				<p:fieldset legend="Veículo">
					<p:panelGrid columns="3" styleClass="borderless">
						<p:outputLabel value="Placa" for="placa" />
						<p:inputText id="placa" label="Placa" value="#{veiculoBean.veiculo.placa}" required="true" maxlength="7" size="50">
							<f:validateRegex pattern="^[A-Z]{3}\d{4}$" />
						</p:inputText>
						<p:message for="placa" />
						<p:outputLabel value="Chassi" for="chassi" />
						<p:inputMask id="chassi" label="Chassi" value="#{veiculoBean.veiculo.chassi}" required="true" mask="**.**.*****.*.*.******" size="50" />
						<p:message for="chassi" />
						<p:outputLabel value="Ano" for="ano" />
						<p:inputText id="ano" label="Ano" value="#{veiculoBean.veiculo.ano}" required="true" maxlength="4" size="50">
							<f:convertNumber integerOnly="true" />
						</p:inputText>
						<p:message for="ano" />
						<p:outputLabel value="Modelo" for="modelo" />
						<p:selectOneMenu id="modelo" value="#{veiculoBean.veiculo.modelo}" required="true" converter="#{modeloConverter}">
							<f:selectItems value="#{veiculoBean.modeloService.findAll()}" var="modelo" itemValue="#{modelo}" itemLabel="#{modelo.nome}" />
						</p:selectOneMenu>
						<p:message for="modelo" />
					</p:panelGrid>
				</p:fieldset>
				<br />
				<p:commandButton id="salvar" value="Salvar"	action="#{veiculoBean.salvar}" update=":growl, :veiculoForm, :datatableForm" icon="ui-icon-disk" />
				<p:commandButton id="novo" value="Novo"	actionListener="#{veiculoBean.novo}" process="@this" update=":veiculoForm" icon="ui-icon-document" />
			</h:form>
			<br />
			<h:form id="datatableForm">
				<p:dataTable id="datatable" var="veiculo"
					value="#{veiculoBean.veiculoService.findAll()}" rows="10" paginator="true"
					paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					currentPageReportTemplate="({currentPage} de {totalPages})" rowsPerPageTemplate="5, 10, 15" emptyMessage="Nenhum registro encontrado.">
					<p:column headerText="Placa">
						<h:outputText value="#{veiculo.placa}" />
					</p:column>
					<p:column headerText="Chassi">
						<h:outputText value="#{veiculo.chassi}" />
					</p:column>
					<p:column headerText="Ano">
						<h:outputText value="#{veiculo.ano}" />
					</p:column>
					<p:column headerText="Marca">
						<h:outputText value="#{veiculo.modelo.marca.nome}" />
					</p:column>
					<p:column headerText="Modelo">
						<h:outputText value="#{veiculo.modelo.nome}" />
					</p:column>
					<p:column style="width: 32px;">
						<p:commandButton icon="ui-icon-pencil" title="Editar" actionListener="#{veiculoBean.editar(veiculo)}" update=":veiculoForm" />
					</p:column>
					<p:column style="width: 32px;">
						<p:commandButton icon="ui-icon-trash" title="Excluir" actionListener="#{veiculoBean.excluir(veiculo)}" update=":growl, :veiculoForm, :datatableForm">
							<p:confirm header="Confirmação" message="Deseja realmente excluir este veículo?" icon="ui-icon-alert" />
						</p:commandButton>
					</p:column>
				</p:dataTable>
			</h:form>
		</p:panel>
	</ui:define>
</ui:composition>

</html>